#ifndef _BT_DEF_H_
#define _BT_DEF_H_

#include "../tree_common.h"

typedef void * elem_t;

typedef struct bt_node_t_
{
	union
	{
		elem_t data;
		intptr_t value;
	};
											
	union
	{
		struct
		{
			struct bt_node_t_ *	l_child;
			struct bt_node_t_ * r_child;
		};
		struct bt_node_t * child_pair[2];
	};

} bt_node_t;

bt_node_t * bt_node_create(void);

/*
 * release the whole tree
 */
void bt_node_release(bt_node_t * root);

bt_node_t * bt_find_node(bt_node_t * root, elem_t e);
size_t bt_height(bt_node_t * root);

typedef int (*bt_for_each_hook)(bt_node_t * node);
typedef int (*bt_for_each_func)(bt_node_t * root, bt_for_each_hook hook);

int bt_r_for_each_pre_order(bt_node_t * root, bt_for_each_hook hook);
int bt_r_for_each_in_order(bt_node_t * root, bt_for_each_hook hook);
int bt_r_for_each_post_order(bt_node_t * root, bt_for_each_hook hook);

int bt_r_for_each_leaf(bt_node_t * root, bt_for_each_hook hook);
int bt_r_like(bt_node_t * r0, bt_node_t * r1);
int bt_r_for_each_in_path_r(bt_node_t * root, elem_t elem, bt_for_each_hook hook);

int bt_for_each_pre_order(bt_node_t * root, bt_for_each_hook hook);
int bt_for_each_in_order(bt_node_t * root, bt_for_each_hook hook);
int bt_for_each_post_order(bt_node_t * root, bt_for_each_hook hook);

int bt_for_each_post_order_x(bt_node_t * root, bt_for_each_hook hook);

int bt_for_each_pre_order0(bt_node_t * root, bt_for_each_hook hook);
int bt_for_each_in_order0(bt_node_t * root, bt_for_each_hook hook);
int bt_for_each_post_order0(bt_node_t * root, bt_for_each_hook hook);

#endif /* _BT_DEF_H_ */
